//
//  OsrffmJLCFMineBankCardViewControllerUidVai.m
//  qcb_ios
//
//  Created by Ji on 2018/8/31.
//  Copyright © 2018年 ski. All rights reserved.
//

#import "OsrffmJLCFMineBankCardViewControllerUidVai.h"
#import "sHkPtEJLCFMineRequestozAYZs.h"
#import "EkiodHJLCFMineBanKCardDataModelLhceQD.h"
#import "XZHNOcJLCFMineBindCardViewControllerMRXeuQ.h"

@interface OsrffmJLCFMineBankCardViewControllerUidVai ()


@property (nonatomic, strong) EkiodHJLCFMineBanKCardDataModelLhceQD *card;

@property (nonatomic, assign) BOOL hasCard;

@end

@implementation OsrffmJLCFMineBankCardViewControllerUidVai

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self addNavigationBar];
    self.navigationBar.title = @"我的银行卡";
    
    self.view.backgroundColor = QTZ_Gray237;

    [self loadData];
}

- (void)loadData
{
    
    [sHkPtEJLCFMineRequestozAYZs bankCardWithParams:nil loadingInView:self.view success:^(ELbxxpJLCFMineBankCardResultModelLJOnsl *card) {
        if ([card.code isEqualToString:@"400"]) {
            self.hasCard = NO;
        } else if ([card.code isEqualToString:@"200"]) {
            if (card.data.userName) {
                self.hasCard = YES;
            }else{
                self.hasCard = NO;
            }
            
        }
        self.card = card.data;
        [self configView];
    } failure:^(NSString *error) {
        [self showNotice:error];
    }];
    
}

- (void)configView
{
    if (!self.hasCard) {
        
//        UILabel *edHyphtipsLabelTVYPVW = [UILabel labelWithText:@"没有绑定银行卡" textColor:QTZ_Gray102 font:FONT(15)];
//        edHyphtipsLabelTVYPVW.centerX = FULL_WIDTH / 2;
//        edHyphtipsLabelTVYPVW.top = NAVBAR_HEIGHT + 35;
//        [self.view addSubview:edHyphtipsLabelTVYPVW];
//
//        UIButton *bindBtn = [[UIButton alloc] initWithFrame:CGRectMake(38, 0, FULL_WIDTH - 76, 40)];
//        bindBtn.bottom = FULL_HEIGHT - 15 - (IPHONEX ? 30 : 0);
//        bindBtn.titleLabel.font = FONT(15);
//        [bindBtn setBackgroundColor:Theme_Color];
//        [bindBtn setTitleColor:QTZ_White forState:0];
//        [bindBtn setTitle:@"绑定" forState:0];
//        bindBtn.layer.cornerRadius = 5;
//        [bindBtn addTarget:self action:@selector(handleBind) forControlEvents:UIControlEventTouchUpInside];
//        [self.view addSubview:bindBtn];
        
        UIImageView *flFGIcbindCardmirovYImg = [[UIImageView alloc] initWithFrame:CGRectMake(10, NAVBAR_HEIGHT + 20, FULL_WIDTH - 20, 150)];
        flFGIcbindCardmirovYImg.image = [UIImage imageNamed:@"icon_mine_flFGIcbindCardmirovY_bg"];
        flFGIcbindCardmirovYImg.userInteractionEnabled = YES;
        [flFGIcbindCardmirovYImg bk_whenTapped:^{
            [self handleBind];
        }];
        [self.view addSubview:flFGIcbindCardmirovYImg];
        
    } else {
        
        UIImageView *bankBgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_mine_bankBg"]];
        bankBgView.centerX = FULL_WIDTH / 2;
        bankBgView.top = NAVBAR_HEIGHT + 20;
        [self.view addSubview:bankBgView];
        
        UIImageView *logoImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 125, 30)];
        [logoImg setOnlineImage:self.card.bankLog];
        logoImg.left = 30;
        logoImg.top = 10;
        [bankBgView addSubview:logoImg];
//        dailyLimit
        UILabel *bankcardNumLabel = [UILabel labelWithText:self.card.bankCardNo textColor:QTZ_White font:FONT(19)];
        bankcardNumLabel.left = logoImg.left;
        bankcardNumLabel.top = bankBgView.height / 2 - 5;
        [bankBgView addSubview:bankcardNumLabel];
        
        UILabel *perLimitLabel = [UILabel labelWithText:[NSString stringWithFormat:@"单笔限额：%@元", self.card.perLimit] textColor:QTZ_White font:FONT(12)];
        perLimitLabel.left = logoImg.left;
        perLimitLabel.bottom = bankBgView.height - 10;
        [bankBgView addSubview:perLimitLabel];
        
        UILabel *dailyLimitLabel = [UILabel labelWithText:[NSString stringWithFormat:@"单日限额：%@元", self.card.dailyLimit] textColor:QTZ_White font:FONT(12)];
        dailyLimitLabel.right = bankBgView.width - 30;
        dailyLimitLabel.bottom = perLimitLabel.bottom;
        [bankBgView addSubview:dailyLimitLabel];
        
        
//        UIButton *unBindBtn = [[UIButton alloc] initWithFrame:CGRectMake(38, 0, FULL_WIDTH - 76, 40)];
//        unBindBtn.bottom = FULL_HEIGHT - 15;
//        unBindBtn.titleLabel.font = FONT(15);
//        [unBindBtn setBackgroundColor:QTZ_White];
//        [unBindBtn setTitleColor:QCB_RED forState:0];
//        [unBindBtn setTitle:@"解绑" forState:0];
//        unBindBtn.layer.cornerRadius = 5;
//        unBindBtn.layer.borderColor = QCB_RED.CGColor;
//        unBindBtn.layer.borderWidth = 1;
//        [unBindBtn addTarget:self action:@selector(handleUnBind) forControlEvents:UIControlEventTouchUpInside];
//        [self.view addSubview:unBindBtn];
        
    }
    
}

- (void)handleBind
{
    XZHNOcJLCFMineBindCardViewControllerMRXeuQ *vc = [XZHNOcJLCFMineBindCardViewControllerMRXeuQ new];
    vc.flFGIcbindCardmirovY = YES;
    vc.bindComplete = ^{
        [self.view removeAllSubviews];
        [self viewDidLoad];
    };
    [[[JinLiCaiFuApplicationEntrace shareEntrance] currentNavController] pushViewController:vc animated:YES];
}

- (void)handleUnBind
{
    XZHNOcJLCFMineBindCardViewControllerMRXeuQ *vc = [XZHNOcJLCFMineBindCardViewControllerMRXeuQ new];
    vc.flFGIcbindCardmirovY = NO;
    vc.card = self.card;
    vc.bindComplete = ^{
        
    };
    [[[JinLiCaiFuApplicationEntrace shareEntrance] currentNavController] pushViewController:vc animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
